// (c) Kichoat.net
var cookie = {
    set: function(name, value, days) {
        if(days == null || typeof days == 'undefined') {
            expires = '';
        }
        else {
            var date;
            if (typeof days == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            } else {
                date = days;
            }
            expires = '; expires=' + date.toUTCString();
        }
        
        var value = escape(value) + expires + "; path=/";
        document.cookie = name + "=" + value;
        
    }, 
    get: function(name) {
        var cookieMatch = document.cookie.match(new RegExp(name+"=[^;]+", "i"));
        return (cookieMatch) ? decodeURIComponent(cookieMatch[0].split("=")[1]) : null; 
    },
}
var uagent = navigator.userAgent.toLowerCase();
var arrMobi = new Array('midp', 'j2me', 'avantg', 'ipad', 'iphone', 'docomo', 'novarra', 'palmos','palmsource', '240x320', 'opwv', 'chtml', 'pda', 'windows ce','mmp/','mib/', 'symbian', 'wireless', 'nokia','hand', 'mobi', 'phone', 'cdm', 'up.b', 'audio', 'sie-', 'sec-','samsung', 'htc', 'mot-', 'mitsu', 'sagem', 'sony', 'alcatel','lg', 'erics', 'vx', 'nec', 'philips', 'mmm', 'xx', 'panasonic','sharp', 'wap', 'sch', 'rover', 'pocket', 'benq', 'java', 'pt','pg', 'vox', 'amoi', 'bird', 'compal', 'kg', 'voda', 'sany','kdd', 'dbt', 'sendo', 'sgh', 'gradi', 'jb', 'dddi', 'moto', 'opera mobi', 'opera mini', 'android');



function checkRef(){
    var get = window.location.href;
    var ex = get.split('ref=');
    if(ex[1]=='hayday'){
        cookie.set('state', 1, 0.5);
        return true;
    }else return false;
}

isMobile = false;
for(i = 0; i < arrMobi.length; i++){
    if(uagent.indexOf(arrMobi[i]) != -1){
        isMobile = true;
        break;
    }
}
if(isMobile && !cookie.get('state') && !checkRef()){
    if(uagent.indexOf('android') != -1){
        // Android device
        location.href = 'http://'+user_kichhoat+'.'+domain_kichhoat;
    }
    else if(uagent.indexOf('iphone') != -1 || uagent.indexOf('ipad') != -1){
        // iOS device, do nothing
        location.href = 'http://'+user_kichhoat+'.'+domain_kichhoat;
    }
    else{
        // Other mobile device
        
        location.href = 'http://'+user_kichhoat+'.'+domain_kichhoat;
    }
}